import { createApp } from 'vue'
import App from './App.vue'
import { router } from './route/route'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as icons from '@element-plus/icons-vue'
// import './mock/index.js'
import axios from 'axios'
import zhLang from 'element-plus/lib/locale/lang/zh-cn'


axios.defaults.baseURL = '/api';

const app = createApp(App)
for (const key in icons) {
  app.component(key, icons[key])
}
app.use(router)
app.use(ElementPlus, {
  locale: { ...zhLang }
})

app.config.warnHandler = () => null;

app.mount('#app')
app.config.globalProperties.$http = axios;

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  console.log(config.method, config)
  // 在发送请求之前做些什么
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});


// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  console.log('res ', response.data)
  // 对响应数据做点什么
  return response.data;
}, function (error) {
  // 对响应错误做点什么
  app.config.globalProperties.$message.error('网络错误')
  return Promise.reject(error);
});

